package common

import "strings"

func DontPanic() {
	if err := recover(); err != nil {

	}
}

const defaultSep = "|"

/*ConcatArray2String 拼接两个数组 （去重）
 * @param arrA
 * @param arrB
 * @param optionalSep
 * @return string
 */
func ConcatArray2String(arrA []string, arrB []string, optionalSep ...string) string {
	sep := defaultSep
	if len(optionalSep) != 0 {
		sep = optionalSep[0]
	}

	m := map[string]struct{}{}

	for _, v := range arrA {
		m[v] = struct{}{}
	}

	for _, v := range arrB {
		m[v] = struct{}{}
	}

	var result []string
	for k := range m {
		result = append(result, k)
	}

	return strings.Join(result, sep)
}

/*RetrieveStringArray 获取字符串数组
 * @param s
 * @param optionalSep
 * @return []string
 */
func RetrieveStringArray(s string, optionalSep ...string) []string {
	sep := defaultSep
	if len(optionalSep) != 0 {
		sep = optionalSep[0]
	}

	return strings.Split(s, sep)
}
